package com.hongliang;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Predicate;

/**
 * @author Hongliang Zhu
 * @create 2021-07-25 11:52
 */
public class Demo1 {

    @Test
    public void test1(){
        List<String> allStrs = Arrays.asList("北京", "天津", "河北", "东京","普京");
        List<String> list = FilterString(allStrs, s ->  s.contains("京"));
        System.out.println(list);

    }

    @Test
    public void test2(){
        happy(900, money -> System.out.println("消费"+money));
    }

    private List<String> FilterString(List<String> list, Predicate<String> predicate){

        List<String> res = new ArrayList<>();

        for (String str: list){
           if(predicate.test(str)){
               res.add(str);
           }
        }
        return res;
    }

    public void happy(int money, Consumer<Integer> consumer){
        consumer.accept(money);
    }

}
